﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Orid.Management.Statistics.Tools.Decomposition.Model;
using Orid.Management.Statistics.Tools.Decomposition.Logic;

using Orid.Management.Common.Job;

namespace Orid.Management.Statistics.Tools.Decomposition.Data
{
    class ChildData :DataBase
    {
        #region 变量定义
         
          protected  StringBuilder sqlText = new StringBuilder();
          protected StringBuilder sqlOrder = new StringBuilder();
          protected StringBuilder sqlParentID = new StringBuilder();

        #endregion

          #region 构造函数 Sql内容

          public ChildData()
        {
            sqlText.Append(" SELECT       [ChildDataID] ");
            sqlText.Append("             ,[OrderID] ");
            sqlText.Append("             ,[DataStoreID] ");
            sqlText.Append("             ,[FileName] ");
            sqlText.Append("             ,[EntryResult] ");
            sqlText.Append("             ,[UpdateDateTime] ");
            sqlText.Append("             ,[ParentDataID] ");
            sqlText.Append("             ,[FinalResult] ");
            sqlText.Append("             ,[CategoryID] ");
            sqlText.Append("             ,[FlowSet] ");
            sqlText.Append("             ,[FlowStatus] ");
            sqlText.Append("             ,[Progress] ");
            sqlText.Append("             ,[FlowTimestamp] ");
            sqlText.Append("             ,[Postion] ");
            sqlText.Append("             ,[Size] ");
            sqlText.Append("             ,[Property] ");
            sqlText.Append("             ,[WordCount] ");
            //sqlText.Append("             ,[IsDelivery] ");//R32修改
            sqlText.Append(" FROM @ChildDatasTable [ChildDatas] with(NOLOCK)");//readpast
            sqlText.Append(" WHERE [ChildDataID] = @ChildDataID ");


            sqlOrder.Append(" SELECT     [ChildDataID] ");
            sqlOrder.Append("             ,[OrderID] ");
            sqlOrder.Append("             ,[ParentDataID] ");
            sqlOrder.Append("             ,[CategoryID] ");
            sqlOrder.Append(" FROM @ChildDatasTable  [ChildDatas] with(NOLOCK)");//readpast
            sqlOrder.Append(" WHERE [OrderID] = @OrderID ");

            sqlParentID.Append(" SELECT   ParentDataID  ");
            sqlParentID.Append(" FROM @ChildDatasTable  [ChildDatas] with(NOLOCK)");//readpast
            sqlParentID.Append(" WHERE [ChildDataID] = @ChildDataID ");
        }

          #endregion

          #region 虚函数

            public virtual List<ModelOrderRecord> GetChildID(Guid orderID)
             {
                 return null;
             }

            public virtual ModelFrameObject GetFrameData(Guid ChildDataID)
            {
                return null;
            }

            public virtual ModelBlockObject GetBlockData(Guid ChildDataID)
            {
                return null;
            }
      
            public virtual ModelJudgeObject GetJudgeData(Guid ChildDataID)
            {
                return null;
            }

            public virtual ModelInputObject GetInputObject(Guid ChildDataID)
            {
                return null;
            }

            public virtual Guid GetParentID(Guid ChildDataID)
            {
                return new Guid ();
            }

            public virtual BlockImage GetBlockImage(Guid FrameID, int Left, int Top, int Width, int Height) { return null; }

            public virtual List<ModelFrameResult> GetFrameResult(Guid ChildDataID)
            {
                return null;
            }

          #endregion 

        //----------------------------------------
        #region protected methor

        protected   ModelFrameObject GetFrameData   (
            Guid ChildDataID, string connectString, string ChildDatasTableName   )
        { 

            ModelFrameObject modelFrame = new ModelFrameObject();

            try
            { 

                sqlText.Replace("@ChildDatasTable", ChildDatasTableName);

                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                {

                    conn.Open();
                    System.Data.SqlClient.SqlParameter[] SqlParameter;
                    SqlParameter = new System.Data.SqlClient.SqlParameter[]
                                 { 
                                     new System.Data.SqlClient.SqlParameter("@ChildDataID",System.Data.SqlDbType.UniqueIdentifier),  

                                 };

                    SqlParameter[0].Value = ChildDataID;
                    Orid.Data.SqlServer.SqlHelper.TimeOut = msTimeOut;

                    SqlDataReader orderReader = Orid.Data.SqlServer.SqlHelper.ExecuteReader(conn, System.Data.CommandType.Text, sqlText.ToString(), SqlParameter);
                    modelFrame = InitFrameModel(orderReader);
                    if (conn.State == System.Data.ConnectionState.Open)
                        conn.Close();

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return modelFrame;

        }
    
        protected   ModelBlockObject GetBlockData   (
           Guid ChildDataID, string connectString, string ChildDatasTableName      )
       {
           

           ModelBlockObject modelBlock = new ModelBlockObject();

           try
           {

               sqlText.Replace("@ChildDatasTable", ChildDatasTableName);

               using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
               {

                   conn.Open();
                   System.Data.SqlClient.SqlParameter[] SqlParameter;
                   SqlParameter = new System.Data.SqlClient.SqlParameter[]
                                { 
                                   new System.Data.SqlClient.SqlParameter("@ChildDataID",System.Data.SqlDbType.UniqueIdentifier),  
                                };


                   SqlParameter[0].Value = ChildDataID;
                   Orid.Data.SqlServer.SqlHelper.TimeOut = msTimeOut;
                   SqlDataReader orderReader = Orid.Data.SqlServer.SqlHelper.ExecuteReader(conn, System.Data.CommandType.Text, sqlText.ToString(), SqlParameter);
                   modelBlock = InitBlockModel(orderReader);



                  

                   if (conn.State == System.Data.ConnectionState.Open)
                       conn.Close();
               }

           }
           catch (Exception ex)
           {
               throw ex;
           }

           return modelBlock;

       }

   
        protected   ModelJudgeObject GetJudgeData  (
              Guid ChildDataID,string connectString ,string ChildDatasTableName  ,Account account  )
          {

              ModelJudgeObject modelJudge = new ModelJudgeObject();

              try
              {
                  sqlText.Replace("@ChildDatasTable", ChildDatasTableName);

                  using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                  {

                      conn.Open();
                      System.Data.SqlClient.SqlParameter[] SqlParameter;
                      SqlParameter = new System.Data.SqlClient.SqlParameter[]
                                   { 
                                      new System.Data.SqlClient.SqlParameter("@ChildDataID",System.Data.SqlDbType.UniqueIdentifier),  
                                    };


                      SqlParameter[0].Value = ChildDataID;
                      Orid.Data.SqlServer.SqlHelper.TimeOut = msTimeOut;
                      SqlDataReader orderReader = Orid.Data.SqlServer.SqlHelper.ExecuteReader(conn, System.Data.CommandType.Text, sqlText.ToString(), SqlParameter);
                      modelJudge = InitJudgeModel(orderReader, account);
                      if (conn.State == System.Data.ConnectionState.Open)
                          conn.Close();

                  }

              }
              catch (Exception ex)
              {
                  throw ex;
              }

              return modelJudge;


          }

        protected  ModelInputObject GetInputObject (
            Guid ChildDataID,string connectString, string ChildDatasTableName,Account account   )
        {

            ModelInputObject modelInput = new ModelInputObject();


            try
            {
                sqlText.Replace("@ChildDatasTable", ChildDatasTableName);

                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                {

                    conn.Open();
                    System.Data.SqlClient.SqlParameter[] SqlParameter;
                    SqlParameter = new System.Data.SqlClient.SqlParameter[]
                                 {                                         
                                    new System.Data.SqlClient.SqlParameter("@ChildDataID",System.Data.SqlDbType.UniqueIdentifier),  
                                  };


                    SqlParameter[0].Value = ChildDataID;
                    Orid.Data.SqlServer.SqlHelper.TimeOut = msTimeOut;
                    SqlDataReader orderReader = Orid.Data.SqlServer.SqlHelper.ExecuteReader(conn, System.Data.CommandType.Text, sqlText.ToString(), SqlParameter);
                    modelInput = InitInputModel(orderReader, account);
                    if (conn.State == System.Data.ConnectionState.Open)
                        conn.Close();

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return modelInput;



        }

        public   List<ModelOrderRecord> GetChildID    (    Guid orderID, string connectString ,string ChildDatasTableName    )
        {
          List<ModelOrderRecord> listModel = new List<ModelOrderRecord>();

          try
          {
              sqlOrder.Replace("@ChildDatasTable", ChildDatasTableName);

              using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
              {

                  conn.Open();
                  System.Data.SqlClient.SqlParameter[] SqlParameter;
                  SqlParameter = new System.Data.SqlClient.SqlParameter[]
                               { 
                                              
                                  new System.Data.SqlClient.SqlParameter("@OrderID",System.Data.SqlDbType.UniqueIdentifier),  

                               };


                  SqlParameter[0].Value = orderID;
                  Orid.Data.SqlServer.SqlHelper.TimeOut = msTimeOut;
                  SqlDataReader reader = Orid.Data.SqlServer.SqlHelper.ExecuteReader(conn, System.Data.CommandType.Text, sqlOrder.ToString(), SqlParameter);

                  listModel = InitOrderRecord(reader);
                  if (conn.State == System.Data.ConnectionState.Open)
                      conn.Close();


              }
          }
          catch (Exception ex)
          {
              throw ex;
          }
          return listModel;


        }

        public   Guid GetParentID(Guid ChildDataID,string connectString, string ChildDatasTableName)
        {
          Guid ParentID;
          try
          {
              sqlParentID.Replace("@ChildDatasTable", ChildDatasTableName);

              using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
              {

                  conn.Open();
                  System.Data.SqlClient.SqlParameter[] SqlParameter;
                  SqlParameter = new System.Data.SqlClient.SqlParameter[]
                               {    
                                  new System.Data.SqlClient.SqlParameter("@ChildDataID",System.Data.SqlDbType.UniqueIdentifier)  

                               };


                  SqlParameter[0].Value = ChildDataID;
                  Orid.Data.SqlServer.SqlHelper.TimeOut = msTimeOut;
                  ParentID = ((Guid)Orid.Data.SqlServer.SqlHelper.ExecuteScalar(conn, System.Data.CommandType.Text, sqlParentID.ToString(), SqlParameter));


                  if (conn.State == System.Data.ConnectionState.Open)
                      conn.Close();


              }
          }
          catch (Exception ex)
          {
              throw ex;
          }

          return ParentID;
        }


        public  BlockImage GetBlockImage(Guid FrameID, int Left, int Top, int Width, int Height,string connectString ,string ChildDatasTableName) 
        {
            BlockImage blockImage =new BlockImage ();
            try
            {
                sqlParentID.Replace("@ChildDatasTable", ChildDatasTableName);

                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                {

                    conn.Open();
                    System.Data.SqlClient.SqlParameter[] SqlParameter;
                    SqlParameter = new System.Data.SqlClient.SqlParameter[]
                               {    
                                  new System.Data.SqlClient.SqlParameter("@ChildDataID",System.Data.SqlDbType.UniqueIdentifier)  

                               };


                    SqlParameter[0].Value = FrameID;
                    Orid.Data.SqlServer.SqlHelper.TimeOut = msTimeOut;

                    SqlDataReader orderReader = Orid.Data.SqlServer.SqlHelper.ExecuteReader(conn, System.Data.CommandType.Text, sqlText.ToString(), SqlParameter);
                     blockImage = InitTrimerBlockModel(orderReader, Left,  Top,  Width,  Height);


                    if (conn.State == System.Data.ConnectionState.Open)
                        conn.Close();


                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return blockImage;
        
        }

        protected List<ModelFrameResult> GetFrameResult(
            Guid ChildDataID, string connectString, string ChildDatasTableName)
        {

            List<ModelFrameResult> modelFrameResultList = new List<ModelFrameResult>();

            try
            {

                sqlText.Replace("@ChildDatasTable", ChildDatasTableName);

                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                {

                    conn.Open();
                    System.Data.SqlClient.SqlParameter[] SqlParameter;
                    SqlParameter = new System.Data.SqlClient.SqlParameter[]
                                 { 
                                     new System.Data.SqlClient.SqlParameter("@ChildDataID",System.Data.SqlDbType.UniqueIdentifier),  

                                 };

                    SqlParameter[0].Value = ChildDataID;
                    Orid.Data.SqlServer.SqlHelper.TimeOut = msTimeOut;

                    SqlDataReader orderReader = Orid.Data.SqlServer.SqlHelper.ExecuteReader(conn, System.Data.CommandType.Text, sqlText.ToString(), SqlParameter);
                    modelFrameResultList = InitFrameModelResult(orderReader);
                    if (conn.State == System.Data.ConnectionState.Open)
                        conn.Close();

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return modelFrameResultList;

        }
        #endregion
        //----------------------------------------

        #region Order

        protected List<ModelOrderRecord> InitOrderRecord(SqlDataReader reader)
        {
            List<ModelOrderRecord> listOrderRecord = new List<ModelOrderRecord>();
            while(reader.Read())
            {
                ModelOrderRecord model = new ModelOrderRecord();
                model.ChildDataID = (Guid)reader["ChildDataID"];
                model.ParentD = (Guid)reader["ParentDataID"];
                model.OrderID = (Guid)reader["OrderID"];
                model.CategoryID = (int)reader["CategoryID"]; //frame 11

                listOrderRecord.Add(model);
            }
            reader.Close();

            return listOrderRecord;

        }

        #endregion

        #region FrameObject
        /// <summary>
        /// Frame
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected ModelFrameObject InitFrameModel(  SqlDataReader reader)
        {
            ModelFrameObject model = new  ModelFrameObject  ();
            string strEntryResult = string.Empty;
            string strProperty = string.Empty;
            while (reader.Read())
            {
                model.FrameID = (Guid)reader["ChildDataID"];
                model.Parentid = (Guid)reader["ParentDataID"];
                model.OrderID = (Guid)reader["OrderID"];
                model.CategoryID = (int)reader["CategoryID"]; //frame 10

                if (reader["DataStoreID"] != DBNull.Value)
                {
                    model.DataStoreID = (Guid)reader["DataStoreID"];
                }

               
                //position
                string strPosition = reader["Postion"].ToString();
                System.Drawing.Point    position = new XmlSerializer<System.Drawing.Point >().XmlDeserialize(strPosition);

                model.X = position.X;
                model.Y = position.Y;

                //Size
                string strSize = reader["Size"].ToString();
                System.Drawing.Size size = new XmlSerializer<System.Drawing.Size>().XmlDeserialize(strSize);
                model.Width = size.Width;
                model.Height = size.Height;


                //录入结果
                strEntryResult = reader["EntryResult"].ToString();

               
                if (reader["Progress"] != DBNull.Value)
                {
                    string xml = reader["Progress"].ToString();

                    model.ListModelProgress =  GetProgress(xml);
                }

               if (reader["Property"] != DBNull.Value)
               {
                   strProperty = reader["Property"].ToString();
               }

               
            }
            reader.Close();

            //从xml里面得到录入结果
            GetFrameEntryResult(ref model, strEntryResult);
            //2011-4-1 获得wordflag
            model.MProperty = GetPropertyField(strProperty);
            return model;
        }

        private void GetFrameEntryResult(ref ModelFrameObject model, string strEntryResult)
        {
         
            //分解录入结果
            ImageInputHistory imageInputHistory = new XmlSerializer<ImageInputHistory>().XmlDeserialize(strEntryResult);
            foreach (JobInputHistory jobInputHistory in imageInputHistory.JobInputHistorys)
            {
                if (jobInputHistory.JobClassID == (int)Logic.JobClass.MTジョブ)
                {
                    //2010-09-18
                    //lidawei 
                    //ma release 25 drop
                    //modelEntryResult.MTPropagationTime =
                    //    GetCost(
                    //    jobInputHistory.PersonHistorys[0].DownLoadDateTime,
                    //    jobInputHistory.PersonHistorys[0].UploadDateTime
                    //);

                    BlcokTrimerResult result = jobInputHistory.PersonHistorys[0].InputResult as BlcokTrimerResult;

                    BlockTrimerContent content = result.Content as BlockTrimerContent;

                    model.MTDuration = result.Duration;
                    model.MTInputDateTime = result.InputDateTime;
                    model.MTBlockCount = content.TrimerBlocks.Length;
                    model.MTComment = result.Comment.ToString();

                }
                else
                    if (jobInputHistory.JobClassID == (int)Logic.JobClass.Trimerジョブ)
                    {
                        //2010-09-18
                        //lidawei
                        //ma release 25 drop
                        //modelEntryResult.TrimerPropagationTime =
                        //    GetCost(
                        //    jobInputHistory.PersonHistorys[0].DownLoadDateTime,
                        //    jobInputHistory.PersonHistorys[0].UploadDateTime
                        //);
                       //2011-4-1
                        if (jobInputHistory.PersonHistorys[0].InputResult is TrimerResult)
                        {
                            TrimerResult result = jobInputHistory.PersonHistorys[0].InputResult as TrimerResult;
                             BlockTrimerContent content = result.Content as BlockTrimerContent;
       
                            model.TrimerDuration = result.Duration;
                            model.TrimerInputDateTime = result.InputDateTime;
                            model.TrimerBlockCount = content.TrimerBlocks != null? content.TrimerBlocks.Length : 0 ;
                            model.TrimerComment = result.Comment.ToString();
                          
                        }
                      
                    }
                    else
                        if (
                            (jobInputHistory.JobClassID == (int)Logic.JobClass.機械仕分ジョブ)
                            ||(jobInputHistory.JobClassID == (int)Logic.JobClass.手動仕分ジョブ)
                            )
                        {
                            ModelDistinguishObject distinguishObject = new ModelDistinguishObject();

                            //2010-09-18
                            //lidawei
                            //ma release 25 drop
                            //distinguishObject.PropagationTime =
                            //       GetCost(
                            //jobInputHistory.PersonHistorys[0].DownLoadDateTime,
                            //jobInputHistory.PersonHistorys[0].UploadDateTime);

                            DistinguishResult distinguishResult =
                            jobInputHistory.PersonHistorys[0].InputResult as DistinguishResult;
                            
                            DistinguishContent distinguishContent = distinguishResult.Content as DistinguishContent;
                            if (distinguishContent != null)
                            {
                                distinguishObject.Result = distinguishContent.MatterType.ToString();

                            }
                            if (distinguishResult != null)
                            {
                                distinguishObject.Duration = distinguishResult.Duration;
                                distinguishObject.InputDateTime = distinguishResult.InputDateTime;
                                if (distinguishResult.Property != null)
                                {
                                    distinguishObject.Transverse = distinguishResult.Property.WordDirection.ToString();
                                }
                                distinguishObject.JobClass = jobInputHistory.JobClassName;
                            }

                            if (jobInputHistory.JobClassID == (int)Logic.JobClass.機械仕分ジョブ)
                            {
                                distinguishObject.JobClass = JobClassAll.機械仕分.ToString();
                                model.MachineDistinguishObject = distinguishObject;
                                
                            }
                            else if (jobInputHistory.JobClassID == (int)Logic.JobClass.手動仕分ジョブ)
                            {
                                distinguishObject.JobClass = JobClassAll.手動仕分.ToString();
                                model.ManuelDistinguishObject = distinguishObject;
                            }

                        }



            }
        }

        #endregion

        #region CheckDataResult FrameResult

        protected List<ModelFrameResult> InitFrameModelResult(SqlDataReader reader)
        {
            ModelFrameResult modelEntryResult = new ModelFrameResult();

            ModelFrameResult modelFinalResult = new ModelFrameResult();
            modelFinalResult.JobClass = JobClassAll.Final;

            string strEntryResult = string.Empty;
            string strFinalResult = string.Empty;
            while (reader.Read())
            {
                modelEntryResult.FrameResultID = modelFinalResult.FrameResultID = (Guid)reader["ChildDataID"];
                modelEntryResult.Parentid = modelFinalResult.Parentid = (Guid)reader["ParentDataID"];
                modelEntryResult.OrderID = modelFinalResult.OrderID= (Guid)reader["OrderID"];
                modelEntryResult.CategoryID = modelFinalResult.CategoryID = (int)reader["CategoryID"]; //frame 10

                if (reader["DataStoreID"] != DBNull.Value)
                {
                    modelEntryResult.DataStoreID = modelFinalResult.DataStoreID= (Guid)reader["DataStoreID"];
                }

                if (reader["Postion"] != DBNull.Value)
                {
                    //position
                    string strPosition = reader["Postion"].ToString();

                    System.Drawing.Point position = new XmlSerializer<System.Drawing.Point>().XmlDeserialize(strPosition);

                    modelEntryResult.X = modelFinalResult.X= position.X;
                    modelEntryResult.Y = modelFinalResult.Y = position.Y;
                }
                if (reader["Size"] != DBNull.Value)
                {
                    //Size
                    string strSize = reader["Size"].ToString();
                    System.Drawing.Size size = new XmlSerializer<System.Drawing.Size>().XmlDeserialize(strSize);
                    modelEntryResult.Width = modelFinalResult.Width = size.Width;
                    modelEntryResult.Height = modelFinalResult.Height = size.Height;
                }

                if (reader["EntryResult"] != DBNull.Value)
                {
                    //录入结果
                    strEntryResult = reader["EntryResult"].ToString();
                }

                if (reader["FinalResult"] != DBNull.Value)
                {
                    //最终结果
                    strFinalResult = reader["FinalResult"].ToString();

                }

                if (reader["Progress"] != DBNull.Value)
                {
                    string xml = reader["Progress"].ToString();

                    modelEntryResult.ListModelProgress = modelFinalResult.ListModelProgress = GetProgress(xml);
                }

               


            }
            reader.Close(); 

            //从xml里面得到录入结果
            GetFrameEntryResult(ref modelEntryResult, strEntryResult);
            GetFrameFinalResult(ref modelFinalResult, strFinalResult);

            List<ModelFrameResult> modelList = new List<ModelFrameResult>();
            modelList.Add(modelEntryResult);
            modelList.Add(modelFinalResult);

            return modelList;
        }

        private void GetFrameEntryResult(ref ModelFrameResult model, string strEntryResult)
        {

            //分解录入结果
            ImageInputHistory imageInputHistory = new XmlSerializer<ImageInputHistory>().XmlDeserialize(strEntryResult);
            foreach (JobInputHistory jobInputHistory in imageInputHistory.JobInputHistorys)
            {
                
                if ((jobInputHistory.JobClassID == (int)Logic.JobClass.Fジョブ) || 
                    (jobInputHistory.JobClassID == (int)Logic.JobClass.Gジョブ) )
                {
                    //TODO:

                    if (jobInputHistory.PersonHistorys[0].InputResult is CheckDataResult)
                    {
                        CheckDataResult result = jobInputHistory.PersonHistorys[0].InputResult as CheckDataResult;
                        CheckResultContent content = result.Content as CheckResultContent; 
                        string opid  =  jobInputHistory.PersonHistorys[0].OpID;

                        if (jobInputHistory.JobClassID == (int)Logic.JobClass.Fジョブ)
                        {
                            GetCheckDataResult(ref model, result, opid, JobClassAll.F);
                        }
                        else if (jobInputHistory.JobClassID == (int)Logic.JobClass.Gジョブ)
                        {
                            GetCheckDataResult(ref model, result, opid, JobClassAll.G);
                           
                        } 
                    }

                } 
            }
        }

        private void GetFrameFinalResult(ref ModelFrameResult model, string strFinalResult)
        {

            //分解录入结果
            PersonInputHistory personInputHistory = new XmlSerializer<PersonInputHistory>().XmlDeserialize(strFinalResult);

            //add by lidawei 2011-1-12            
            if ((personInputHistory != null) &&(personInputHistory.InputResult !=null))
            {
                CheckDataResult result = personInputHistory.InputResult as CheckDataResult;
                CheckResultContent content = result.Content as CheckResultContent;
                string opid = string.Empty;
                
                GetCheckDataResult(ref model, result, opid, JobClassAll.Final);
            
            }
        }
        
        private void GetCheckDataResult(ref ModelFrameResult model, CheckDataResult result, string operatorID, JobClassAll jobclass)
        {
          
                if (jobclass == JobClassAll.G)
                {
                    model.GInputDateTime = result.InputDateTime;
                    model.GLoginName = operatorID;
                    model.GDuration = result.Duration;
                    model.GComment  = result.Comment.ToString();
                }
                else if (jobclass == JobClassAll.F)
                {
                    model.FInputDateTime = result.InputDateTime;
                    model.FLoginName = operatorID;
                    model.FDuration = result.Duration;
                    model.FComment = result.Comment.ToString();

                }


            CheckResultContent content = result.Content as CheckResultContent;

            if ((content != null) && (content.Results != null))
            {
            
                foreach (ResultObject item in content.Results)
                {
                    ModelFrameResult.ModelFrameDetailReuslt itemResult = new ModelFrameResult.ModelFrameDetailReuslt();
                   
                    
                    itemResult.JobClass = jobclass; 
                    itemResult.Rect = item.Rect;
                    itemResult.IsChange = item.IsChange;
                    itemResult.ImageType =  item.ResultItem.ImageType;

                    if (model.resultItem == null)
                        model.resultItem = new List<ModelFrameResult.ModelFrameDetailReuslt> ();


                    if (item.ResultItem.ListItemResult ==null)
                        itemResult.Result = item.ResultItem.ResultString;
                    else
                        itemResult.Result = item.ResultItem.ToString();
 
                    model.resultItem.Add(itemResult); 
              
                }
            }
        }

        #endregion CheckDataResult FrameResult 

        #region TrimerBlock
     
        private  BlockImage  InitTrimerBlockModel( SqlDataReader    reader,int Left, int Top,int  Width,  int Height)
        {
            BlockImage model = new BlockImage();
            string strEntryResult = string.Empty;

            while (reader.Read())
            {              
                //录入结果
                strEntryResult = reader["EntryResult"].ToString();



            }
            reader.Close();

            if (strEntryResult != string.Empty)
            {
                //分解录入结果
                ImageInputHistory imageInputHistory = new XmlSerializer<ImageInputHistory>().XmlDeserialize(strEntryResult);
                foreach (JobInputHistory jobInputHistory in imageInputHistory.JobInputHistorys)
                {
                    if (jobInputHistory.JobClassID == (int)Logic.JobClass.Trimerジョブ)
                    {
                        BlockTrimerContent content = null;
                        if (jobInputHistory.PersonHistorys[0].InputResult is TrimerResult)
                        {
                            TrimerResult result = jobInputHistory.PersonHistorys[0].InputResult as TrimerResult; 
                            content = result.Content as BlockTrimerContent;
                        }

                        //2011-4-12 
                        if (content != null && content.TrimerBlocks != null)
                        {
                            foreach (BlockImage item in content.TrimerBlocks)
                            {
                                if ((item.Left == Left) &&
                                   (item.Top == Top) &&
                                   (item.Width == Width) &&
                                   (item.Height == Height))
                                {
                                    model = item;
                                    break;
                                }
                            }
                        }

                    }
                }
            }

            return model;
        }
        #endregion

        #region Block
        /// <summary>
        /// Block
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected ModelBlockObject InitBlockModel(SqlDataReader reader)
        {
            ModelBlockObject model = new ModelBlockObject();
            string strEntryResult = string.Empty; 
            while (reader.Read())
            {
                model.BlockID = (Guid)reader["ChildDataID"];
                model.Frameid = (Guid)reader["ParentDataID"];
                model.OrderID = (Guid)reader["OrderID"];
                model.CategoryID = (int)reader["CategoryID"]; //frame 11

                if ( reader["DataStoreID"] != DBNull.Value)
                {
                    model.DataStoreID = (Guid)reader["DataStoreID"];
                }
                //position
                string strPosition = reader["Postion"].ToString();
                OrderedPostion position = new XmlSerializer<OrderedPostion>().XmlDeserialize(strPosition);

                model.X = position.Location.X;
                model.Y = position.Location.Y;

                //Size
                string strSize = reader["Size"].ToString();
                System.Drawing.Size size = new XmlSerializer<System.Drawing.Size>().XmlDeserialize(strSize);
                model.Width = size.Width;
                model.Height = size.Height;

                model.JobClass =  JobClassAll.OCR;
                
                //录入结果
                strEntryResult = reader["EntryResult"].ToString();     

                if (reader["Progress"] != DBNull.Value)
                {
                    string xml = reader["Progress"].ToString();

                    model.ListModelProgress = GetProgress(xml);
                }

                if (reader["Property"] != DBNull.Value)
                {
                    string xmlProperty = reader["Property"].ToString();

                    model.MProperty = GetPropertyField( xmlProperty);
                }

            }
            reader.Close();
 

            GetBlockEntryResult(ref model, strEntryResult); 

            return model;
        }

        private void GetBlockEntryResult(ref  ModelBlockObject model, string strEntryResult)
        {
            //分解录入结果
            ImageInputHistory imageInputHistory = new XmlSerializer<ImageInputHistory>().XmlDeserialize(strEntryResult);
            foreach (JobInputHistory jobInputHistory in imageInputHistory.JobInputHistorys)
            {
                //印刷体 经过ocr处理的
                if (jobInputHistory.JobClassID == (int)Logic.JobClass.OCRジョブ)
                {
                    //2010-09-18
                    //lidawei
                    //ma release 25 drop
                    //modelEntryResult.OcrPropagationTime =
                    //    GetCost(
                    //    jobInputHistory.PersonHistorys[0].DownLoadDateTime,
                    //    jobInputHistory.PersonHistorys[0].UploadDateTime
                    //);

                    OCRResult oCResult = jobInputHistory.PersonHistorys[0].InputResult as OCRResult;

                    OCRContent oCRContent = oCResult.Content as OCRContent;


                    model.OcrInputDateTime = oCResult.InputDateTime;
                    model.OCRComment = oCResult.Comment.ToString();
                    model.OcrDuration = oCResult.Duration;
                    //if (oCResult.Property != null)
                    //{
                    //    model.Transverse = oCResult.Property.WordDirection.ToString();
                    //}

                    //2010-06-17 去除
                    //modelEntryResult.WordDirection = oCRContent.BlockInformation.WordDirection.ToString();
                    //modelEntryResult.WordFlag = oCRContent.BlockInformation.WordFlag.ToString();
                    //modelEntryResult.ManuscriptType = oCRContent.BlockInformation.ScriptType.ToString();
                    //modelEntryResult.WordType = oCRContent.BlockInformation.WordType.ToString();
                    model.InputObjectCount = oCRContent.InputObjects.Length;

                }

                /*2011-4-13 drop 以下内容从属性中得到

                //在Trimer中处理的结果记录下载
                //2010-06-17
                //lidawei
                if (jobInputHistory.JobClassID == (int)Logic.JobClass.Trimerジョブ)
                {
                    foreach (PersonInputHistory personItem in jobInputHistory.PersonHistorys)
                    { 
                        if (personItem.InputResult.GetType().Equals(typeof( Orid.Management.Common.Job.BlcokTrimerResult  )))
                        {
                            BlcokTrimerResult trimerResult = (BlcokTrimerResult)personItem.InputResult;

                            BlockTrimerContent blockTrimerContent = (BlockTrimerContent)trimerResult.Content;
                            //
                        

                            foreach (BlockImage blockImage in blockTrimerContent.TrimerBlocks)
                            {
                                model.WordDirection = blockImage.WordDirection.ToString();
                                model.WordFlag      = blockImage.WordFlag.ToString();
                                model.ManuscriptType= blockImage.ScriptType.ToString();
                                model.WordType      = blockImage.WordType.ToString();
                                model.ImageType     = blockImage.ImageType.ToString();
                                model.MatterType    = blockImage.MatterType.ToString(); 
                               
                            }
                        }

                    }
                }
                */

            }
        }
        #endregion

        #region Judge

     /*

        /// <summary>
        /// Judge结果 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="DownLoadID">0 ：α ; 1:β </param>
        /// <returns></returns>
        protected ModelJudgeObject InitJudgeModelSingal(SqlDataReader reader,int DownLoadID)
        {
            ModelJudgeObject modelEntryResult = new  ModelJudgeObject ();
            while (reader.Read())
            {
                modelEntryResult.JudgeID = (Guid)reader["ChildDataID"];
                modelEntryResult.InputobjectID = (Guid)reader["ParentDataID"];
                modelEntryResult.OrderID = (Guid)reader["OrderID"];
                modelEntryResult.CategoryID = (int)reader["CategoryID"]; //frame 11

                //position
                string strPosition = reader["[Postion]"].ToString();
                OrderedPostion position = new XmlSerializer<OrderedPostion>().XmlDeserialize(strPosition);

                modelEntryResult.X = position.Location.X;
                modelEntryResult.Y = position.Location.Y;

                //Size
                string strSize = reader["[Size]"].ToString();
                System.Drawing.Size size = new XmlSerializer<System.Drawing.Size>().XmlDeserialize(strSize);
                modelEntryResult.Width = size.Width;
                modelEntryResult.Height = size.Height;


                //录入结果
                string strEntryResult = reader["EntryResult"].ToString();



                //分解录入结果
                ImageInputHistory imageInputHistory = new XmlSerializer<ImageInputHistory>().XmlDeserialize(strEntryResult);
                foreach (JobInputHistory jobInputHistory in imageInputHistory.JobInputHistorys)
                {
                    if (jobInputHistory.JobClassID == (int)Logic.JobClass.候補結果判定ジョブ)
                    {
                        ModelJudgeResult judgeResult = new ModelJudgeResult();
                     

                        //DownLoadID : 0 ,1

                        if (DownLoadID.Equals(0))
                        {
                            modelEntryResult.JobClass = judgeResult.JobClass=JobClassAll.α;
                      
                        }
                        else if(DownLoadID.Equals(1))
                        {
                            modelEntryResult.JobClass = judgeResult.JobClass = JobClassAll.β;
                            
                        }

                        PersonInputHistory inputHistory = jobInputHistory.PersonHistorys[DownLoadID];
                        CandidacyJudgeResult candidacyJudgeResult = inputHistory.InputResult as CandidacyJudgeResult;
                        CandidacyJudgeContent candidacyJudgeContent = inputHistory.InputResult.Content  as  CandidacyJudgeContent;

                        modelEntryResult.PropagationTime = GetCost(inputHistory.DownLoadDateTime,inputHistory.UploadDateTime);
                        judgeResult.JudgeID = modelEntryResult.JudgeID;                     
                        judgeResult. LoginName = account.GetLoginName(inputHistory.AccountID);
                        modelEntryResult. Duration =  candidacyJudgeResult.Duration;

                        modelEntryResult.Comment = judgeResult.Comment = candidacyJudgeResult.Comment.ToString();

                        judgeResult.CandidacyJudgeResult =  GetCandidacyJudgeResultAndInputResult(candidacyJudgeContent); 
                         
                        modelEntryResult.Transverse = candidacyJudgeResult.Transverse.ToString();

                    
                    }

                }

            }
            reader.Close();

            return modelEntryResult;
        }

        */
        /// <summary>
        /// Judge结果 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected ModelJudgeObject InitJudgeModel(SqlDataReader reader,Account account)
        {
            ModelJudgeObject model = new ModelJudgeObject();
            string strEntryResult = string.Empty;
            while (reader.Read())
            {
                model.JudgeID = (Guid)reader["ChildDataID"];
                model.InputobjectID = (Guid)reader["ParentDataID"];
                model.OrderID = (Guid)reader["OrderID"];
                model.CategoryID = (int)reader["CategoryID"]; //frame 11

                if (reader["DataStoreID"] != DBNull.Value)
                {
                    model.DataStoreID = (Guid)reader["DataStoreID"];
                }

                //position
                string strPosition = reader["Postion"].ToString();
                OrderedPostion position = new XmlSerializer<OrderedPostion>().XmlDeserialize(strPosition);

                //2010 4 1追加
                model.Index = position.Index;
                model.X = position.Location.X;
                model.Y = position.Location.Y;

                //Size
                string strSize = reader["Size"].ToString();
                System.Drawing.Size size = new XmlSerializer<System.Drawing.Size>().XmlDeserialize(strSize);
                model.Width = size.Width;
                model.Height = size.Height;


                //录入结果
                strEntryResult = reader["EntryResult"].ToString();

                model.JobClass = Orid.Management.Statistics.Tools.Decomposition.Logic.JobClass.判定ジョブ;

                if (reader["Progress"] != DBNull.Value)
                {
                    string xml = reader["Progress"].ToString();

                    model.ListModelProgress = GetProgress(xml);
                }

                //FinalResult
                //2010-04-21 lidawei
                if (reader["FinalResult"] != DBNull.Value)
                {

                    string strFinalResult = reader["FinalResult"].ToString();

                    if ((strFinalResult != null) && (strFinalResult != string.Empty))
                    {
                        
                    
                    PersonInputHistory personInputHistory = new XmlSerializer<PersonInputHistory>().XmlDeserialize(strFinalResult);
                    if ((personInputHistory != null) && (personInputHistory.IsFinalResult))
                    {

                        if (personInputHistory.InputResult.GetType().Equals(typeof(Orid.Management.Common.Job.CandidacyJudgeResult )))
                        {
                            if (personInputHistory.InputResult.Content != null)
                            {
                                CandidacyJudgeContent content = personInputHistory.InputResult.Content as CandidacyJudgeContent;


                                for (int i = 0; i < content.InitObject.CandidacyResult.Count; i++)
                                {
                                    OCRUnitObject item = content.InitObject.CandidacyResult[i];

                                    ModelCandidacyJudgeResult result = new ModelCandidacyJudgeResult();

                                    //2010-06-04
                                    List<string> tempList = new List<string>();
                                    foreach (string c in item.OCRResult)
                                    {
                                        tempList.Add(c.ToString());
                                    }
                                    result.ListCandidacyJudgeResult = tempList;
                                    

                                    result.Result = content.WordResults[i].Resutl;
                                    result.IsNullResult = content.WordResults[i].IsNullResult;
                                   
                                    model.FinalResult.Add(result);

                                }

                                //content.InitObject.CandidacyResult
                            }
                        }
                    }
                    }

                }
                      
                        
              }

            reader.Close(); 
            
            GetJudgeEntryResult(account,ref  model, strEntryResult);
            
            if (model.ListJudgeResult.Count == 0)
            {
                model = null;
            }
            return model;


        }

        private void GetJudgeEntryResult(Account account,ref  ModelJudgeObject model, string strEntryResult)
        {
            //分解录入结果
            ImageInputHistory imageInputHistory = new XmlSerializer<ImageInputHistory>().XmlDeserialize(strEntryResult);

            foreach (JobInputHistory jobInputHistory in imageInputHistory.JobInputHistorys)
            {

                if (jobInputHistory.JobClassID == (int)Logic.JobClass.候補結果判定ジョブ)
                {


                    //int i = 0;
                    foreach (PersonInputHistory inputHistory in jobInputHistory.PersonHistorys)
                    {
                        ModelJudgeResult judgeResult = new ModelJudgeResult();

                        CandidacyJudgeResult candidacyJudgeResult = inputHistory.InputResult as CandidacyJudgeResult;
                        CandidacyJudgeContent candidacyJudgeContent = inputHistory.InputResult.Content as CandidacyJudgeContent;
                        //此时不知道jobClass
                        //最后通过Job中的AccountID 来确定judgeResult中的jobClass
                        //if (i.Equals(0))
                        //{
                        //    judgeResult.JobClass = JobClassAll.α;

                        //}
                        //else if (i.Equals(1))
                        //{
                        //    judgeResult.JobClass = JobClassAll.β;

                        //}
                        judgeResult.JobClass = JobClassAll.unKnow;
                        
                        judgeResult.WordCount = candidacyJudgeContent.InitObject.CandidacyResult.Count;

                        //2010-09-18
                        //lidawei
                        //ma release 25 drop
                        //modelEntryResult.PropagationTime += GetCost(inputHistory.DownLoadDateTime, inputHistory.UploadDateTime);
                        model.Duration += candidacyJudgeResult.Duration;

                        judgeResult.JudgeID = model.JudgeID;
                     
                        judgeResult.LoginName = account.GetLoginName(inputHistory.AccountID);
                        judgeResult.Comment = judgeResult.Comment = candidacyJudgeResult.Comment.ToString();
                        //ma release 25 drop
                        //judgeResult.PropagationTime = GetCost(inputHistory.DownLoadDateTime, inputHistory.UploadDateTime);
                        judgeResult.CandidacyJudgeResult = GetCandidacyJudgeResultAndInputResult(candidacyJudgeContent);

                        foreach (ModelCandidacyJudgeResult item in judgeResult.CandidacyJudgeResult)
                        {
                            if (item.IsNullResult)
                            //if (IsErrorResult(item.Result))
                                judgeResult.ErrorCount++;
                            
                        }

                     
                        judgeResult.Duration = candidacyJudgeResult.Duration;
                        judgeResult.InputTime = candidacyJudgeResult.InputDateTime;

                        if (candidacyJudgeResult.Property != null)
                        {
                            model.Transverse = candidacyJudgeResult.Property.WordDirection.ToString();
                            judgeResult.Transverse = candidacyJudgeResult.Property.WordDirection.ToString();
                        }
                        model.ListJudgeResult.Add(judgeResult);

                      //  i++;
                    }

                }

            }
        }

        

        #endregion

        #region Input

        protected ModelInputObject InitInputModel(SqlDataReader reader,Account account)
        {
            //查找ABDE
            ModelInputObject model = new  ModelInputObject();
            string strEntryResult=string.Empty, strFinalResult=string.Empty;

             while (reader.Read())
             {
                 model.InputId = (Guid)reader["ChildDataID"];
                 model.CategoryID = (int)reader["CategoryID"]; //frame 11
                 Guid blockId =  (Guid)reader["ParentDataID"];
                 model.OrderID = (Guid)reader["OrderID"];

                 if (reader["DataStoreID"] != DBNull.Value)
                 {
                     model.DataStoreID = (Guid)reader["DataStoreID"];
                 }

                 if (model.CategoryID == 2)
                 {
                     model.FrameId = blockId;
                     model.BlockId = new Guid();
                 }
                 else if (model.CategoryID == 13)
                 {
                     model.BlockId = blockId;
                 }
                 else if (model.CategoryID == 11)
                 {
                     model.FrameId = blockId;
                     model.BlockId = new Guid();
                 }
                
                 

                 //position
                 string strPosition = reader["Postion"].ToString();
                 OrderedPostion position = new XmlSerializer<OrderedPostion>().XmlDeserialize(strPosition);

                 model.Index = position.Index;
                 model.X = position.Location.X;
                 model.Y = position.Location.Y;

                 //Size
                 string strSize = reader["Size"].ToString();
                 System.Drawing.Size size = new XmlSerializer<System.Drawing.Size>().XmlDeserialize(strSize);
                 model.Width = size.Width;
                 model.Height = size.Height;


                 //录入结果
                 strEntryResult = reader["EntryResult"].ToString();
                 
                 strFinalResult = reader["FinalResult"].ToString();



                 if (reader["Progress"] != DBNull.Value)
                 {
                     string xml = reader["Progress"].ToString();

                     model.ListModelProgress = GetProgress(xml);
                 }


                 if (reader["Property"] != DBNull.Value)
                 {
                     string xmlProperty = reader["Property"].ToString();

                     model.MProperty = GetPropertyField( xmlProperty);
                 }

                 
                 ////R32 Add
                 //if (reader["IsDelivery"] != DBNull.Value)
                 //{
                 //    model.IsDelivery =Convert .ToInt32( reader["IsDelivery"]);
                 //}
             }

            

            reader.Close();

            if (model.InputId.ToString().ToLower() == "17A53C0A-0D25-4EE2-97B4-DC0D5D5CF08A".ToLower())
            {
                string a = "";
            }
         
            GetInputEntryResult(account,ref  model, strEntryResult, strFinalResult);
            return model;
        }

        private void GetInputEntryResult(Account account,ref  ModelInputObject model, string strEntryResult, string strFinalResult)
        {
            try
            {
                #region 分解录入结果
                //分解录入结果

                ImageInputHistory imageInputHistory = new XmlSerializer<ImageInputHistory>().XmlDeserialize(strEntryResult);
                foreach (JobInputHistory jobInputHistory in imageInputHistory.JobInputHistorys)
                {

                    if (jobInputHistory.JobClassID == (int)Logic.JobClass.OCRジョブ)
                    {
                        #region OCRジョブ

                        OCRResult oCResult = jobInputHistory.PersonHistorys[0].InputResult as OCRResult;

                        if (oCResult.Content != null)
                        {
                            OCRContent oCRContent = oCResult.Content as OCRContent;
                            //2011-4-13 图像方向从property获得
                            //if (oCResult.Property != null)
                            //{

                            //    //图片方向 
                            //   // model.Transverse = oCResult.Property.WordDirection.ToString();
                            //}

                            //文字数
                            foreach ( InputObject itemInputObject in oCRContent.InputObjects)
                            {
                                foreach ( JudgeObject itemJudgeObject in itemInputObject.JudgeObjects)
                                {
                                    model.WorldCounts += itemJudgeObject.CandidacyResult.Count;

                                }

                            }
                        }

                        #endregion                      
                        
                    }
                    else if (jobInputHistory.JobClassID == (int)Logic.JobClass.候補結果判定ジョブ)
                    {
                        #region 候補結果判定ジョブ

                        PersonInputHistory inputHistory = jobInputHistory.PersonHistorys[0];
                        AttachJudgeResultResult attachJudgeResultResult = inputHistory.InputResult as AttachJudgeResultResult;
                        //Αβ照和标记                        
                        model.αβAttachFlag = inputHistory.IsFinalResult;
                        AttachWordsResult attachWordsResult = attachJudgeResultResult.Content as AttachWordsResult;
                        //2010-4-6 修改 无论照和失败成功 照和结果都有意义
                        //if (modelEntryResult.αβAttachFlag)
                        //{
                            model.αβAttachWordsResult = attachWordsResult.Result;
                        //}

                        foreach (WordResult itemWordResult in attachWordsResult.Words)
                        {
                            //2010-1-4-1 李大伟
                            if (itemWordResult.IsNullResult)
                            //结果誤り
                            //if (IsErrorResult(itemWordResult.Resutl))
                            {
                                model.JudgeErrorCount += 1;
                            }
                        }

                        //xml结果中没有以下内容 
                        ModelEntryObject ΑEntryObject = new ModelEntryObject();
                        ΑEntryObject.InputID = model.InputId;
                        ΑEntryObject.JobClass = JobClassAll.α;
                        model.αEntry = ΑEntryObject;

                        ModelEntryObject βEntryObject = new ModelEntryObject();
                        βEntryObject.InputID = model.InputId;
                        βEntryObject.JobClass = JobClassAll.β;
                        model.βEntry = βEntryObject;

                        #endregion
                    }
                    else if (jobInputHistory.JobClassID == (int)Logic.JobClass.新ABジョブ)
                    {
                        #region 新ABジョブ

                        //此处可能有多组结果存在 当前无法预知那些是有效的结果
                        foreach (PersonInputHistory item in jobInputHistory.PersonHistorys)
	                    {


                            int accountID = item.AccountID;
                            ModelEntryObject entryObject = new ModelEntryObject();
                            entryObject.InputID = model.InputId;
                            entryObject.LoginName = account.GetLoginName(accountID);
                            
                            //2010-09-18
                            //lidawei
                            //ma release 25 drop                            
                            //entryObject.PropagationTime = GetCost(item.DownLoadDateTime, item.UploadDateTime);
                            entryObject.Duration = item.InputResult.Duration;
                            entryObject.Comment = item.InputResult.Comment.ToString();
                            entryObject.Result = ((AttachWordsResult)item.InputResult.Content).Result;
                            //AB的录入结果
                            WordResult[] result = ((AttachWordsResult)item.InputResult.Content).Words;
                            for (int i = 0; i < result.Length; i++)
                            {
                                if (result[i].IsNullResult)
                                {
                                    entryObject.EntryWords += result[i].Resutl ;//.Resutl.Value;
                                }
                                
                            }
                            entryObject.IsFinalResult = item.IsFinalResult;

                            model.ABEntryList.Add(entryObject);                           


                        }
                        #endregion

                    }
                    else if  (jobInputHistory.JobClassID == (int)Logic.JobClass.ABジョブ)
                       
                    {

                        #region ABジョブ
 
                        //此处可能有多组结果存在 当前无法预知那些是有效的结果
                        foreach (PersonInputHistory item in jobInputHistory.PersonHistorys)
                        {


                            int accountID = item.AccountID;
                            ModelEntryObject entryObject = new ModelEntryObject();
                            entryObject.InputID = model.InputId;
                            //2010-11-20 修改 accountid 有虚拟的，从DB读取会失败
                            entryObject.LoginName = item.OpID;
                                //account.GetLoginName(accountID);

                            //2010-09-18
                            //lidawei
                            //ma release 25 drop
                            //entryObject.PropagationTime = GetCost(item.DownLoadDateTime, item.UploadDateTime);
                            entryObject.Duration = ((EntryResult)item.InputResult).Duration;
                            entryObject.Comment = ((EntryResult)item.InputResult).Comment.ToString();

                            //2010-10-29 lidawei 修改 
                            //entryresult的content 类型由 string 变更为 itemresult类型
                            if (((EntryResult)item.InputResult).Content is Orid.Management.Common.Job.ItemResult[])
                            {
                               entryObject.Result  = ((EntryResult)item.InputResult).ToString();
                            }
                            else  if (((EntryResult)item.InputResult).Content is string)
                            {
                                entryObject.Result = ((EntryResult)item.InputResult).Content as string;
                            }
                         
                            entryObject.IsFinalResult = item.IsFinalResult;
                        
                            model.ABEntryList.Add( entryObject); 

                      }

                        #endregion
                    }
                    else if (jobInputHistory.JobClassID == (int)Logic.JobClass.新Dジョブ)
                    {
                        #region 新Dジョブ
                        foreach (PersonInputHistory itemPersonInputHistory in jobInputHistory.PersonHistorys)
                        {

                            ModelEntryObject entryResult = new ModelEntryObject();

                            entryResult.LoginName = itemPersonInputHistory.OpID;
                            //    account.GetLoginName(itemPersonInputHistory.AccountID);
                            
                            //2010-09-18
                            //lidawei
                            //ma release 25 drop
                            //entryResult.PropagationTime = GetCost(itemPersonInputHistory.DownLoadDateTime,itemPersonInputHistory.UploadDateTime);

                            entryResult.IsFinalResult = itemPersonInputHistory.IsFinalResult;

                            entryResult.Comment = ((AttachWordPositionResult)itemPersonInputHistory.InputResult).Comment.ToString();
                            entryResult.Duration = ((AttachWordPositionResult)itemPersonInputHistory.InputResult).Duration;
                            entryResult.Result = ((WordPositionResult)((AttachWordPositionResult)itemPersonInputHistory.InputResult).Content).Result;

                            entryResult.InputID = model.InputId;
                            entryResult.JobClass = JobClassAll.D;

                            model.DEntryList.Add( entryResult);
                        }
                        #endregion

                    }
                    else if (jobInputHistory.JobClassID == (int)Logic.JobClass.CDジョブ)
                    {
                        #region CDジョブ
                        foreach (PersonInputHistory itemPersonInputHistory in jobInputHistory.PersonHistorys)
                        {

                            ModelEntryObject entryResult = new ModelEntryObject();

                            entryResult.LoginName = itemPersonInputHistory.OpID;
                                //account.GetLoginName(itemPersonInputHistory.AccountID);

                            //2010-09-18
                            //lidawei
                            //ma release 25 drop
                            //entryResult.PropagationTime = GetCost(itemPersonInputHistory.DownLoadDateTime,itemPersonInputHistory.UploadDateTime);

                            entryResult.IsFinalResult = itemPersonInputHistory.IsFinalResult;
                            entryResult.Comment = ((EntryResult)itemPersonInputHistory.InputResult).Comment.ToString()
    ;
                            entryResult.Duration = ((EntryResult)itemPersonInputHistory.InputResult).Duration;
                             
                            //2010-10-29 lidawei 修改 
                            //entryresult的content 类型由 string 变更为 itemresult类型
                            if (((EntryResult)itemPersonInputHistory.InputResult).Content is Orid.Management.Common.Job.ItemResult[])
                            {
                                entryResult.Result = ((EntryResult)itemPersonInputHistory.InputResult).ToString();
                            }
                            else if (((EntryResult)itemPersonInputHistory.InputResult).Content is string)
                            {
                                entryResult.Result = ((EntryResult)itemPersonInputHistory.InputResult).Content as string;
                            }

                            entryResult.InputID = model.InputId;
                            entryResult.JobClass = JobClassAll.D;

                            model.DEntryList.Add( entryResult);
                        }
                        #endregion
                    }
                    else if (jobInputHistory.JobClassID == (int)Logic.JobClass.新Eジョブ)
                    {

                        #region 新Eジョブ
                        foreach (PersonInputHistory itemPersonInputHistory in jobInputHistory.PersonHistorys)
                        {

                            ModelEntryObject entryResult = new ModelEntryObject();

                            entryResult.LoginName = itemPersonInputHistory.OpID;
                            //account.GetLoginName(itemPersonInputHistory.AccountID);

                            //2010-09-18
                            //lidawei
                            //ma release 25 drop
                             //entryResult.PropagationTime = GetCost(itemPersonInputHistory.DownLoadDateTime,itemPersonInputHistory.UploadDateTime);

                            entryResult.IsFinalResult = itemPersonInputHistory.IsFinalResult;

                            entryResult.Comment = ((AttachWordPositionResult)itemPersonInputHistory.InputResult).Comment.ToString();
                            entryResult.Duration = ((AttachWordPositionResult)itemPersonInputHistory.InputResult).Duration;
                            entryResult.Result = ((WordPositionResult)((AttachWordPositionResult)itemPersonInputHistory.InputResult).Content).Result;

                            entryResult.InputID = model.InputId;
                            entryResult.JobClass = JobClassAll.E;

                            model.EEntryList.Add( entryResult);
                        }
                        #endregion
                    }

                    else if (jobInputHistory.JobClassID == (int)Logic.JobClass.Eジョブ)
                    {
                        #region Eジョブ
                        foreach (PersonInputHistory itemPersonInputHistory in jobInputHistory.PersonHistorys)
                        {

                            ModelEntryObject entryResult = new ModelEntryObject();

                            entryResult.LoginName = itemPersonInputHistory.OpID;
                                //account.GetLoginName(itemPersonInputHistory.AccountID);

                            //2010-09-18
                            //lidawei
                            //ma release 25 drop
                            //entryResult.PropagationTime = GetCost(itemPersonInputHistory.DownLoadDateTime,itemPersonInputHistory.UploadDateTime);

                            entryResult.IsFinalResult = itemPersonInputHistory.IsFinalResult;
                            entryResult.Comment = ((EntryResult)itemPersonInputHistory.InputResult).Comment.ToString()
    ;
                            entryResult.Duration = ((EntryResult)itemPersonInputHistory.InputResult).Duration;

                            //2010-10-29 lidawei 修改 
                            //entryresult的content 类型由 string 变更为 itemresult类型
                            if (((EntryResult)itemPersonInputHistory.InputResult).Content is Orid.Management.Common.Job.ItemResult[])
                            {
                                entryResult.Result = ((EntryResult)itemPersonInputHistory.InputResult).ToString();
                            }
                            else if (((EntryResult)itemPersonInputHistory.InputResult).Content is string)
                            {
                                entryResult.Result = ((EntryResult)itemPersonInputHistory.InputResult).Content as string;
                            }

                            entryResult.InputID = model.InputId;
                            entryResult.JobClass = JobClassAll.E;

                            model.EEntryList.Add( entryResult);
                        }
                        #endregion
                    }

                    else if (jobInputHistory.JobClassID == (int)Logic.JobClass.EntryFinalジョブ)
                    {
                    }
                    else if (jobInputHistory.JobClassID == (int)Logic.JobClass.Trimerジョブ)
                    {
                        BlcokTrimerResult  Result = jobInputHistory.PersonHistorys[0].InputResult as BlcokTrimerResult;
                    
                        //2010-07-01修改
                        //这个属性现在已经取消在MA侧
                        //modelEntryResult.Transverse = Result.Property.WordDirection.ToString();

                        BlockTrimerContent blockTrimerContent = (BlockTrimerContent)Result.Content;


                        //foreach (BlockImage blockImage in blockTrimerContent.TrimerBlocks)
                        //{
                           
                        //    //2011-4-13 drop
                        //   // model.ImageType = blockImage.ImageType.ToString();
                        //    //2010-07-01修改
                        //    //model.Transverse = blockImage.WordDirection.ToString();
                        //}

                        
                    }
                    else if (jobInputHistory.JobClassID == (int)Logic.JobClass.判定ジョブ)
                    {
                        foreach (PersonInputHistory itemPersonInputHistory in jobInputHistory.PersonHistorys)
                        {

                            ModelEntryObject entryResult = new ModelEntryObject();

                            entryResult.LoginName = itemPersonInputHistory.OpID;
                          
                            entryResult.IsFinalResult = itemPersonInputHistory.IsFinalResult;

                            if (itemPersonInputHistory.InputResult is JudgeResult)
                            {
                                entryResult.Result = 
                                    ((Orid.Management.Common.Job.IsOKState)(((JudgeResult)itemPersonInputHistory.InputResult).Content)).ToString();  
                                
                                entryResult.Duration = ((JudgeResult)itemPersonInputHistory.InputResult).Duration;
                            }


                            string ocrResult = string.Empty;

                            if (((JudgeResult)itemPersonInputHistory.InputResult).OCRResult != null)
                            {

                                foreach (ItemResult itemResult in ((JudgeResult)itemPersonInputHistory.InputResult).OCRResult)
                                {
                                    if (!string.IsNullOrEmpty(ocrResult))
                                        ocrResult += Environment.NewLine;

                                    ocrResult += itemResult.ToString();
                                }

                         
 
                                //ocr识别的结果存放在ocrEntry里面
                                model.OcrEntry = new ModelEntryObject { Result = ocrResult ,SplitResult =   ((JudgeResult) itemPersonInputHistory.InputResult).ToSplit()};
                            }
                           

                            

                            entryResult.InputID = model.InputId;
                             

                            model.JudgeEntryList.Add(entryResult);
                        }
                    }



                }

                #endregion

                #region 分解最终结果

                if (!strFinalResult.Equals(String.Empty))
                {

                    PersonInputHistory personInputHistory = new XmlSerializer<PersonInputHistory>().XmlDeserialize(strFinalResult);

                    //2010 05- 13 Add by lidawei
                    if ((personInputHistory != null) && (personInputHistory.InputResult  != null) )
                    {
                         model.FinalEntry = new ModelEntryObject();

                        if (model.CategoryID == 2)
                        {
                            //2010-10-29 lidawei 修改 
                            //entryresult的content 类型由 string 变更为 itemresult类型
                            if ((personInputHistory.InputResult as EntryResult).Content is Orid.Management.Common.Job.ItemResult[])
                            {
                                model.FinalEntry.Result = (personInputHistory.InputResult as EntryResult).ToString();

                                model.FinalEntry.SplitResult = (personInputHistory.InputResult as EntryResult).ToSplit();

                            }
                            //else if ((personInputHistory.InputResult as EntryResult).Content is string)
                            //{
                            //    model.FinalEntry.Result = (personInputHistory.InputResult as EntryResult).Content.ToString();
                            //}

                            model.FinalEntry.Comment = (personInputHistory.InputResult as EntryResult).Comment.ToString();
                        }
                        else if (model.CategoryID == 13)
                        {
                            if (personInputHistory.InputResult.GetType().ToString().Equals(typeof(Orid.Management.Common.Job.AttachWordPositionResult)))
                            {
                                if ((personInputHistory.InputResult as AttachWordPositionResult).Content != null)
                                {
                                    model.FinalEntry.Result = ((personInputHistory.InputResult as AttachWordPositionResult).Content as WordPositionResult).Result;
                                    model.FinalEntry.Comment = (personInputHistory.InputResult as AttachWordPositionResult).Comment.ToString();
                                }
                            }
                            else if (personInputHistory.InputResult.GetType().Equals(typeof(Orid.Management.Common.Job.AttachJudgeResultResult)))
                            {

                                if ((personInputHistory.InputResult as AttachJudgeResultResult).Content != null)
                                {
                                    model.FinalEntry.Result = ((personInputHistory.InputResult as AttachJudgeResultResult).Content as AttachWordsResult).Result;
                                    model.FinalEntry.Comment = (personInputHistory.InputResult as AttachJudgeResultResult).Comment.ToString();

                                }
                            }
                        }
                        else if (model.CategoryID == 11)
                        {
                            if (personInputHistory.InputResult is JudgeResult)
                            {
                                ////Final 结果  存放ocr识别结果
                                //if ((personInputHistory.InputResult as JudgeResult).Content is Orid.Management.Common.Job.IsOKState)
                                //{
                                //    //2011-3-1
                                //    //final result  中的判断结果
                                //    string finalResult = string.Empty;
                                //    foreach (ItemResult itemResult in ((JudgeResult)personInputHistory.InputResult).OCRResult)
                                //    {
                                //        if (finalResult.Length > 0)
                                //            finalResult += Environment.NewLine;

                                //       finalResult += itemResult.ToString();
                                //    }

                                //    model.FinalEntry.Result = finalResult;

                                    
                                //}

                                model.FinalEntry.Result = (personInputHistory.InputResult as JudgeResult).ToString();
                                model.FinalEntry.SplitResult = (personInputHistory.InputResult as JudgeResult).ToSplit();

                            }
                            else if (personInputHistory.InputResult is EntryResult)
                            {
                                model.FinalEntry.Result = (personInputHistory.InputResult as EntryResult).ToString();
                                //2011-3-1
                                model.FinalEntry.Comment = (personInputHistory.InputResult as EntryResult).Comment.ToString();

                                model.FinalEntry.SplitResult =  (personInputHistory.InputResult as EntryResult) .ToSplit();
                            }
                        }
                    }
                }
                #endregion

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region 找到候补结果中的ocr结果和录入结果

        /// <summary>
        /// 在候补xml中得到 候补的ocr结果和录入结果
        /// </summary>
        /// <param name="candidacyJudgeContent"></param>
        /// <returns></returns>
        private List<ModelCandidacyJudgeResult> GetCandidacyJudgeResultAndInputResult(CandidacyJudgeContent candidacyJudgeContent)
        {
            List<ModelCandidacyJudgeResult> listCandidacyJudgeResult = new List<ModelCandidacyJudgeResult>();

            int jCount = candidacyJudgeContent.InitObject.CandidacyResult.Count;
          
            for (int j = 0; j < jCount; j++)
            {
                ModelCandidacyJudgeResult candidacyJudgeResult = new ModelCandidacyJudgeResult();

                //2010-06-04
                List<string> tempList = new List<string>();
                foreach (string c in candidacyJudgeContent.InitObject.CandidacyResult[j].OCRResult)
                {
                    tempList.Add(c.ToString());
                }
                 candidacyJudgeResult.ListCandidacyJudgeResult =tempList;

                //candidacyJudgeContent.InitObject.CandidacyResult[j].OCRResult;

                 candidacyJudgeResult.Result =
                candidacyJudgeContent.WordResults[j].Resutl;

                 candidacyJudgeResult.IsNullResult = candidacyJudgeContent.WordResults[j].IsNullResult;

                 listCandidacyJudgeResult.Add(candidacyJudgeResult);
            }

            return listCandidacyJudgeResult;
        }

        #endregion

        #region 判断候补结果是否== 誤り
        //此处代码取消
        //2010-04-01

        //private bool IsErrorResult(string value)
        //{
        //    bool bFlag = false;
        //    if (value.Equals(""))
        //        bFlag = true;
        //    return bFlag;
        //}

        #endregion
    }
}
